<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>grid</title>
  <style>
    html,body{
      margin: 0;
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    .list{
      position: relative;
      display: grid;
      width: 300px;
      grid-template-columns: repeat(3,1fr);
      list-style: none;
      padding: 0;
      counter-reset: count;
      gap: 2px;
    }
    .item{
      aspect-ratio: 1; /*宽高比1:1*/
      background-color: #eee;
    }
    .item:nth-child(9)~.item{ /*选择第9个以后的元素*/
      position: absolute;
      width: calc(100% / 3 - 1px);
      counter-increment: count; /* 从第10个开始计数 */
      visibility: hidden;
      right: 0;
      bottom: 0;
    }
    .item:nth-child(9)~.item:last-child::before{
        visibility: visible;
        background-color: rgba(0,0,0,.2);
    }
    .item:nth-child(9)~.item::before{
      content: '+' counter(count);
      display: grid;
      height: 100%;
      place-content: center;
      font-size: 30px;
      color: #fff;
    }
  </style>
</head>
<body>
  <ul class="list" id="list">
    <li class="item"></li>
    <li class="item"></li>
    <li class="item"></li>
    <li class="item"></li>
    <li class="item"></li>
    <li class="item"></li>
    <li class="item"></li>
    <li class="item"></li>
  </ul>
  <div>
    <button onclick="add()">add</button>
    <button onclick="remove()">remove</button>
  </div>

  <script>
    function add() {
      const item = document.createElement('li');
      item.className = "item";
      list.append(item)
    }
    function remove() {
      list.removeChild(list.lastElementChild)
    }
  </script>
</body>
</html>